package com.m3839.sdk.anti.js;

import android.content.Context;
import android.webkit.JavascriptInterface;

import com.m3839.sdk.anti.core.AntiManager;
import com.m3839.sdk.common.base.BaseJsInterface;
import com.m3839.sdk.common.base.UIStackManager;
import com.m3839.sdk.common.core.Constant;
import com.m3839.sdk.common.util.HandlerUtils;
import com.m3839.sdk.common.util.LogUtils;

/**
 * @description: RealNameJsInterface
 *
 * @author ChenBaoyang
 * @date 8/2/21 11:05
 */
public class RealNameJsInterface extends BaseJsInterface {

    private static final String TAG = "RealNameJsInterface";

    public RealNameJsInterface(Context context) {
        super(context);
    }

    /**
     * h5实名认证提交结果返回
     * @param code
     */
    @JavascriptInterface
    public void onRealNameCallback(int code, String msg) {
        LogUtils.flog(TAG, "onRealNameCallback= $code===msg=$msg");
        onAuthNameCallBack(code, msg);
    }

    private void onAuthNameCallBack(int code, String msg) {
        HandlerUtils.runOnMainThread(new Runnable() {
            @Override
            public void run() {
                UIStackManager.getInstance().finishFragment(Constant.HYKB_TAG_FRAGMENT_ANTI);
                UIStackManager.getInstance().finishFragment(Constant.HYKB_TAG_FRAGMENT_ANTI_REAL_NAME);
                UIStackManager.getInstance().finishFragment(Constant.HYKB_TAG_FRAGMENT_PAY_LIMIT);
                AntiManager.getInstance().onBeat();
            }
        });
    }

    /**
     * h5实名认证关闭弹窗
     * @param code
     */
    @JavascriptInterface
    public void onRealNameClose(int code, String msg) {
        HandlerUtils.runOnMainThread(new Runnable() {
            @Override
            public void run() {
                UIStackManager.getInstance().finishFragment(Constant.HYKB_TAG_FRAGMENT_ANTI_REAL_NAME);
                AntiManager.getInstance().onBeat();
            }
        });
    }
}